#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include "parser.h"
#include "findwidget.h"

#include <QtGui/QMainWindow>
#include <QtGui/QPlainTextEdit>
#include <QtGui/QTreeWidget>
#include <QtGui/QTableWidget>

class MainWindow : public QMainWindow
{
    Q_OBJECT
protected:
    void closeEvent(QCloseEvent *event);

public:
    MainWindow();
	
	QTabWidget *tabWidget; // Container for fields of information
    QTextEdit *textEdit; // Container for source texts
    QTreeWidget *treeWidget; // Container for tree by makefile
    QTableWidget *tableWidgetVar; // Container for variables
    QTableWidget *tableWidgetTarget; // Container for variables

    FindWidget *findWidget; // Widget with function - Find

private slots:
    void newFile();
    void open();
    bool save();
    bool saveAs();
    void find();
    void build();
    void about();
    void documentWasModified();

	void findCurrStr(); // Find in all tabs
    void clearPaintTab(); // Clear paint in all tabs
	
private:
    QString curFile; // Name of current open file
    QBrush *brush;

    void findInTab (QTextEdit *text); // Find substring and paint in QTextEdit
    void findInTab (QTreeWidget *tree); // Find substring and paint in QTreeWidget
    void  findInTree(QTreeWidgetItem *item, QList<QTreeWidgetItem *> *findList); // Recurse round of tree with find substring
    void findInTab (QTableWidget *table); // Find substring and paint in QTableWidget

    void clearInTab (QTextEdit *text); // Clear paint in QTextEdit
    void clearInTab (QTreeWidget *tree); // Clear paint in QTreeWidget
    void clearInTree(QTreeWidgetItem *item, QTreeWidget *tree); // Recurse round of tree with clear paint
    void clearInTab (QTableWidget *table); // Clear paint in QTableWidget

    void createActions(); // Create and discribe actions
    void createMenus(); // Create and discribe menus
    void createToolBars(); // Create and discribe tool bars
    void createStatusBar(); // Create and discribe status bar
    bool maybeSave();
    bool maybeSaveBeforeBuild();
    void loadFile(const QString &fileName);
    void buildFile(const QString &fileName);
    bool saveFile(const QString &fileName);
    void setCurrentFile(const QString &fileName);
    QString getCurrentFile();

    QMenu *fileMenu;
    QMenu *editMenu;
    QMenu *buildMenu;
    QMenu *helpMenu;
    QToolBar *fileToolBar;
    QToolBar *buildToolBar;
    QToolBar *editToolBar;
    QAction *newAct;
    QAction *openAct;
    QAction *saveAct;
    QAction *saveAsAct;
    QAction *exitAct;
    QAction *buildAct;
    QAction *undoAct;
    QAction *redoAct;
    QAction *cutAct;
    QAction *copyAct;
    QAction *pasteAct;
    QAction *findAct;
    QAction *aboutAct;
};

#endif // MAINWINDOW_H
